/*
 * can_cfg.h
 *
 *  Created on: 2023��4��11��
 *      Author: chenwangang
 */

#ifndef BSP_BSP_CAN_CAN_CFG_H_
#define BSP_BSP_CAN_CAN_CFG_H_

#include "Cpu.h"

#define CAN_MSG_QUEUE_LENGTH         16
#define queueSendDONT_BLOCK			( 0UL ) // 往队列发送的时候，不阻塞

/* Rx and Tx mailbox number configure */
#define RX_MAILBOX_FUN_ID       (1u)
#define RX_MAILBOX_PHY_ID       (2u)
#define RX_MAILBOX_1_NORMAL     (3u)
#define RX_MAILBOX_2_NORMAL     (4u)
#define RX_MAILBOX_3_NORMAL     (5u)
#define RX_MAILBOX_4_NORMAL     (8u)
#define TX_MAILBOX_UDS          (6u)
#define TX_MAILBOX_NORMAL       (7u)

#define TX_MAILBOX_1            (9u)


/* Rx message ID, ID type, ID mask configure */
#define	RX_FUN_ADDR_ID          0x18da5536u
#define RX_FUN_ADDR_ID_TYPE     CAN_MSG_ID_EXT
#define RX_FUN_ADDR_ID_MASK     0xFFFFFFFFu

#define	RX_PHY_ADDR_ID          0x18da5535u
#define	RX_PHY_ADDR_ID_TYPE     CAN_MSG_ID_EXT
#define RX_PHY_ADDR_ID_MASK     0xFFFFFFFFu

#define RX_MSG_ID_GATE          (0x210)
#define	RX_MSG_ID_GATE_TYPE     CAN_MSG_ID_STD
#define RX_MSG_ID_GATE_MASK     0x2FF

#define RX_MSG_ID_HTCU          (0x220)
#define	RX_MSG_ID_HTCU_TYPE     CAN_MSG_ID_STD
#define RX_MSG_ID_HTCU_MASK     0x5F0

#define RX_MSG_ID_SENSOR        (0x601)
#define	RX_MSG_ID_SENSOR_TYPE   CAN_MSG_ID_STD
#define RX_MSG_ID_SENSOR_MASK   0x6FF

#define RX_MSG_ID_MUSICLOUD     (0x230)
#define	RX_MSG_ID_MUSIC_TYPE    CAN_MSG_ID_STD
#define RX_MSG_ID_MUSIC_MASK    0x2FF


/* TX message ID, ID type configure */
#define	TX_RESP_ADDR_ID         0x18da3555u
#define	TX_RESP_ADDR_ID_TYPE    CAN_MSG_ID_EXT

#define	TX_ADDR_ID              DOMAIN_BEHIND
#define	TX_ID_TYPE              CAN_MSG_ID_STD

#define	TX_ID_1                 (0x111)
#define	TX_ID_2                 (0x122)
#define	TX_ID_3                 (0x133)
#define	TX_ID_4                 (0x144)
#define	TX_ID_5                 (0x155)
#define	TX_ID_6                 (0x166)
#define	TX_ID_7                 (0x177)
#define	TX_ID_8                 (0x188)
#define	TX_ID_9                 (0x199)


/* UDS service num */
#define SERVICE_10          (0x10u)
#define SERVICE_10_02       (0x02u)
/*-----------------------------------------------------------*/

typedef void (*tpfTxSuccesfullCallBack)(void);
typedef struct
{
    uint32_t usTxID;                        /*tx can id*/
    uint8_t ucTxMailBox;                    /*used tx mail box*/
    flexcan_msgbuff_id_type_t TxID_Type;    /* rx mask ID type:  Standard ID or Extended ID*/
    tpfTxSuccesfullCallBack pfCallBack;
} tTxMsgConfig;

typedef struct
{
    uint8_t usRxMailBox;                    /*used rx mail box*/
    uint32_t usRxID;                        /*rx can id*/
    uint32_t usRxMask;                      /*rx mask*/
    flexcan_msgbuff_id_type_t RxID_Type;	/* rx mask ID type:  Standard ID or Extended ID*/
} tRxMsgConfig;
/*-----------------------------------------------------------*/

extern can_buff_config_t buff_RxTx_Cfg;
/* Define receive buffer */
extern can_message_t g_can_recv_msg;
extern can_message_t g_gate_can_recv_msg;
extern can_message_t g_htcu_can_recv_msg;
extern can_message_t g_sensor_can_recv_msg;
extern can_message_t g_musicloud_can_recv_msg;
/*rx can message num*/
extern const uint8_t g_rx_can_msg_id_num;
/*RX can message config*/
extern const tRxMsgConfig g_rx_msg_config[];
/*TX can message config*/
extern const tTxMsgConfig g_tx_msg_config[];
/*tx can message num*/
const uint8_t g_tx_can_msg_id_num;

extern can_message_t g_can_g_send_msg;
extern can_message_t g_can_eol_recv_msg;
extern can_message_t g_can_eol_g_send_msg;

#endif /* BSP_BSP_CAN_CAN_CFG_H_ */
